package master.userInterface;

import master.*;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class NetworkCreationFrame extends JFrame implements ActionListener{
	WorkspaceContext c;
	JTextField qubits, name;
	public NetworkCreationFrame(WorkspaceContext c){
		JPanel contents = new JPanel();
		contents.setLayout(new GridLayout(3,2));
		this.c = c;
		this.getContentPane().add(contents);
		contents.add(new JLabel("Qubit Number:"));
		contents.add(new JLabel("Name:"));
		qubits = new JTextField();
		name = new JTextField();
		contents.add(qubits);
		contents.add(name);
		JButton accept = new JButton("Create");
		contents.add(accept);
		accept.addActionListener(this);
		this.setTitle("Create Quantum Network");
		this.setSize(400,100);
		this.setResizable(false);
	}
	public void actionPerformed(ActionEvent e) {
		int n = Integer.parseInt(qubits.getText());
		if(name.getText().length()==0){
			c.createWorkspace(new QuantumNetwork(new QuantumRegister(n)));
		}else{
			c.createWorkspace(new QuantumNetwork(new QuantumRegister(n)),name.getText());
		}
		this.dispose();
	}
}
